package com.blb.educourseservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blb.config.RabbitMQConfig;
import com.blb.educourseservice.service.ICourseOrientationService;
import com.blb.educourseservice.service.ICourseService;
import com.blb.educourseservice.service.ICourseTypeService;
import com.blb.pojo.Course;
import com.blb.pojo.CourseOrientation;
import com.blb.pojo.CourseType;
import com.blb.pojo.ResponseResult;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("course")
public class CourseController {
    @Resource
    private ICourseService iCourseService;
    @Resource
    private ICourseTypeService iCourseTypeService;
    @Resource
    private ICourseOrientationService iCourseOrientationService;

    @GetMapping("all")
    public ResponseResult<List<Course>> getAll(){
        List<Course> allCourses = iCourseService.getAllCourses();
        return ResponseResult.ok(allCourses);
    }
    @GetMapping("{id}")
    public ResponseResult getById(@PathVariable Long id){
        Course course = iCourseService.getCourseById(id);
        return ResponseResult.ok(course);
    }
    @GetMapping("type")
    public  ResponseResult getAllType(){
        List<CourseType> list = iCourseTypeService.list();
        return ResponseResult.ok(list);
    }
    @GetMapping("orientation-parent")
    public ResponseResult getAllOrientationParent(){
        List<CourseOrientation> parent_id = iCourseOrientationService.list(new QueryWrapper<CourseOrientation>().eq("parent_id", 0));
        return ResponseResult.ok(parent_id);
    }
    @GetMapping("orientation-children")
    public ResponseResult getAllOrientationChildren(@RequestParam int id){
        List<CourseOrientation> byParent = iCourseOrientationService.getByParent(id);
       return ResponseResult.ok(byParent);
    }



}
